package ibmetp.mis.controller.role;

import ibmetp.mis.common.Constants;
import ibmetp.mis.common.Message;
import ibmetp.mis.service.RoleService;
import ibmetp.mis.service.UserService;
import ibmetp.mis.serviceImpl.RoleServiceImpl;
import ibmetp.mis.serviceImpl.UserServiceImpl;
import ibmetp.mis.vo.Role;
import ibmetp.mis.vo.User;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

/**
 * Servlet implementation class RoleUpdateServlet
 */
public class RoleUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RoleUpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("Calling RoleUpdateServlet...");
		request.setCharacterEncoding(Constants.ENCODING_UTF8);
		
		//获取用户参数
		Role role=new Role();
		role.setRoleId(Long.valueOf(request.getParameter("roleId")));
		role.setRoleName(request.getParameter("roleName"));
		role.setDescript(request.getParameter("descript"));

		
		//更新用户
		RoleService rs=new RoleServiceImpl();		
		String result=rs.updateRole(role);
		System.out.println(role);
		
		//如果有返回消息，则将消息发回页面
		if(result!=null){			
			response.setCharacterEncoding(Constants.ENCODING_UTF8);
			response.getWriter().print(JSONObject.fromObject(new Message(result)));
		}
	}

}
